package net.hn.hnms.biz.steelyard.controller;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import net.hn.hnms.biz.steelyard.request.SteelyardHistoryReq;
import net.hn.hnms.biz.steelyard.service.ISteelyardService;
import net.hn.hnms.biz.steelyard.vo.SteelyardHistoryVO;
import net.hn.hnms.biz.steelyard.vo.SteelyardNowVO;
import net.hn.hnms.biz.steelyard.vo.SteelyardStatisticsVO;
import net.hn.hnms.sys.common.core.domain.R;
import net.hn.hnms.sys.common.core.domain.ResponsePage;
import net.hn.hnms.sys.common.core.web.controller.BaseController;
import net.hn.hnms.sys.common.mybatis.core.page.PageQuery;
import net.hn.hnms.sys.common.satoken.config.AutoSetMineCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.Date;
import java.util.List;

/**
 * @author Wang Jingrui
 * @date 2022/8/24 14:28
 */
@Api(value = "发运管理模块", tags = {"发运管理模块"})
@RestController
@RequestMapping("/steelyard")
public class SteelyardController extends BaseController {

    @Autowired
    private ISteelyardService steelyardService;

    /**
     * 实时数据
     */
    @ApiOperation("实时数据")
//    @SaCheckPermission("steelyard:now")
    @GetMapping("/now")
    @AutoSetMineCode
    public R<ResponsePage<SteelyardNowVO>> now(PageQuery pageQuery, @ApiParam(value = "煤矿编码") String mineCode) {
        return R.ok(steelyardService.now(pageQuery,mineCode));
    }

    /**
     * 历史数据
     */
    @ApiOperation("历史数据")
//    @SaCheckPermission("steelyard:history")
    @GetMapping("/history")
    @AutoSetMineCode
    public R<ResponsePage<SteelyardHistoryVO>> history(SteelyardHistoryReq req, PageQuery pageQuery) {
        return R.ok(steelyardService.history(req, pageQuery));
    }

    /**
     * 统计分析 饼图
     */
    @ApiOperation("统计分析")
//    @SaCheckPermission("steelyard:statistics")
    @GetMapping("/pie")
    @AutoSetMineCode
    public R<List<SteelyardStatisticsVO>> pieChart(@RequestParam(value = "dateTime",required = false)
                                                 @DateTimeFormat(pattern = "yyyy-MM")
                                                 Date dateTime, @ApiParam(value = "煤矿编码") String mineCode) {
        return R.ok(steelyardService.pieChart(dateTime,mineCode));
    }

    /**
     * 统计分析 柱状图
     */
    @ApiOperation("统计分析")
//    @SaCheckPermission("steelyard:statistics")
    @GetMapping("/column")
    @AutoSetMineCode
    public R<List<SteelyardStatisticsVO>> columnChart(@RequestParam(value = "dateTime", required = false)
                                                    @DateTimeFormat(pattern = "yyyy-MM")
                                                    Date dateTime,@ApiParam(value = "煤矿编码") String mineCode) {
        return R.ok(steelyardService.columnChart(dateTime,mineCode));
    }

    @ApiOperation("获取实时产量信息")
    @GetMapping("/nowLink")
    @AutoSetMineCode
    public R<Double> nowLink(@ApiParam(value = "煤矿编码") String mineCode) {
        return R.ok(steelyardService.nowLink(mineCode));
    }

    @ApiOperation("获取年最大产量")
    @GetMapping("/maxForYearLink")
    @AutoSetMineCode
    public R<Double> maxForYearLink(@ApiParam(value = "煤矿编码") String mineCode) {
        return R.ok(steelyardService.maxForYearLink(mineCode));
    }

}
